from sqlalchemy import create_engine
from sqlalchemy.ext.asyncio import create_async_engine, async_sessionmaker, AsyncSession
from sqlalchemy.orm import DeclarativeBase, Session, sessionmaker

from config import settings


# 定义数据库基类
class Base(DeclarativeBase):
    pass


# =============================================== 同步构建数据库操作对象 =============================================== #
engine = create_engine(url=settings.SQLITE_URL)
SessionLocal = sessionmaker(expire_on_commit=False, autoflush=False, bind=engine)


def getDB() -> Session:
    return SessionLocal()
